package com.yf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
public class HelloController {
    @RequestMapping("/books")
    public String greeting(Model model){
    	String str = "学习SpringBoot整合Thymeleaf";
        model.addAttribute("desc",str);
        return "index";
    }
    @GetMapping("/getCode/{code}")
    @ResponseBody
    public String getCode(@PathVariable String code){
        int count = 0;
        List<String> codes = new ArrayList<>();
        codes.add("001892");
        codes.add("169300");
        codes.add("721188");
//        List<String> codes = Arrays.asList("001892", "169300", "721188");
        do{
            if(!codes.contains(code)){
                codes.add(code);
                System.out.println(count);
                break;
            }else{
                count++;
            }
            System.out.println(count);
        }while (count<100);
        System.out.println(codes);
        return code;
    }
}

